package com.gxa.mall.controller;

import com.gxa.mall.common.CommonResult;
import com.gxa.mall.model.Sell;
import com.gxa.mall.service.SellService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 销售单
 */
@RestController
@ResponseBody
@RequestMapping(path = "/sell")
public class SellController {
    @Autowired
    SellService sellService;



    /**
     * 查询全体销售信息
     * @param
     * @return
     */
    @RequestMapping(path = "/toseeksell")
    public CommonResult<List<Sell>> toseekemployee(){
        CommonResult commonResult=null;
        try {
         List<Sell> list=   sellService.toseeksell();
            commonResult=new CommonResult(200,"供货商查询成功",list);
            return commonResult;
        }catch (Exception e){
            e.printStackTrace();
            commonResult=new CommonResult(200,"供货商查询失败",null);
        }
        return commonResult;
    }

    /**
     * 添加销售单
     * @param sell
     * @return
     */
    @RequestMapping(path = "/addsell")
    public CommonResult addsell(Sell sell){
        CommonResult commonResult=null;
        try {
            sellService.addsell(sell);
            commonResult=new CommonResult(200,"添加成功",null);
        }catch (Exception e){
            e.printStackTrace();
            commonResult=new CommonResult(200,"添加失败",null);
        }
        return commonResult;
    }



    /*模糊查询*/
    @RequestMapping(path = "/tolikeseek")
    public CommonResult<List<Sell>> tolikeseek(String text){
        CommonResult commonResult=null;
        try {
            List<Sell> list=   sellService.tolikeseek(text);
            commonResult=new CommonResult(200,"供货商查询成功",list);
            return commonResult;
        }catch (Exception e){
            e.printStackTrace();
            commonResult=new CommonResult(200,"供货商查询失败",null);
        }
        return commonResult;
    }


/*保存修改的员工*/
    @RequestMapping(path = "/savesell")
    public CommonResult savesell(Sell sell){
        CommonResult commonResult=null;
        try {
            sellService.savesell(sell);
            commonResult=new CommonResult(200,"添加成功",null);
        }catch (Exception e){
            e.printStackTrace();
            commonResult=new CommonResult(200,"添加失败",null);
        }
        return commonResult;
    }


    /*根据id查询表单信息*/
    @RequestMapping(path = "/toupdata")
    public CommonResult toupdata(Integer id){
        CommonResult commonResult=null;
        try {
          Sell sell = sellService.toupdata(id);
            commonResult=new CommonResult(200,"查询成功",sell);
        }catch (Exception e){
            e.printStackTrace();
            commonResult=new CommonResult(200,"查询失败",null);
        }
        return commonResult;
    }

   /*根据id删除表单*/
    @RequestMapping(path = "/toremove")
    public CommonResult toremove(Integer id){
        CommonResult commonResult=null;
        try {
            sellService.toremove(id);
            commonResult=new CommonResult(200,"删除成功",null);
        }catch (Exception e){
            e.printStackTrace();
            commonResult=new CommonResult(200,"删除失败",null);
        }
        return commonResult;
    }


   /* *//**
     * 按结果查询员工信息
     * @param text 查询框中的内容
     * @return
     *//*


    *//**
     * 修改员工
     * @param
     * @return
     *//*


    @RequestMapping(path = "/savesupplier")
    public CommonResult saveemployee(Supplier supplier){
        CommonResult commonResult=null;
        try {
            supplierService.saveemployee(supplier);
            commonResult=new CommonResult(200,"添加成功",null);
        }catch (Exception e){
            e.printStackTrace();
            commonResult=new CommonResult(200,"添加失败",null);
        }
        return commonResult;
    }



    @RequestMapping(path = "/addsupplier")
    public CommonResult addemployee(Supplier supplier){
        CommonResult commonResult=null;
        try {
              supplierService.addemployee(supplier);
                commonResult=new CommonResult(200,"添加成功",null);
        }catch (Exception e){
            e.printStackTrace();
            commonResult=new CommonResult(200,"添加失败",null);
        }
        return commonResult;
    }
    *//**
     * 根据id查询员工信息
     *//*
    @RequestMapping(path = "/toupdata")
    public CommonResult toupdata(Integer id){
        CommonResult commonResult=null;
        try {
          Supplier supplier=  supplierService.toupdata(id);
            commonResult=new CommonResult(200,"查询成功",supplier);
        }catch (Exception e){
            e.printStackTrace();
            commonResult=new CommonResult(200,"查询失败",null);
        }
        return commonResult;
    }

    *//**
     * 根据id删除员工
     * @param id 要删除的员工id
     * @return
     *//*
    @RequestMapping(path = "/toremove")
    public CommonResult toremove(Integer id){
        CommonResult commonResult=null;
        try {
            supplierService.toremove(id);
            commonResult=new CommonResult(200,"删除成功",null);
        }catch (Exception e){
            e.printStackTrace();
            commonResult=new CommonResult(200,"删除失败",null);
        }
        return commonResult;
    }

    *//**
     * 修改员工信息
     *//*
*/
}
